package ml.preprocessing;

import ml.LatchedRunnable;
import ml.UpAndCountDownLatch;
import ml.WekaUtil;
import weka.core.Instances;
import weka.filters.unsupervised.instance.Resample;

public class FilterResampleRunnable extends LatchedRunnable {

	private final Instances data;
	private final String outputFile;
	private final int randomSeed;
	private final double sampleSizePercent;

	public FilterResampleRunnable(UpAndCountDownLatch latch, Instances data,
			String outputFile, int randomSeed, double sampleSizePercent) {
		super(latch);
		this.data = data;
		this.outputFile = outputFile;
		this.randomSeed = randomSeed;
		this.sampleSizePercent = sampleSizePercent;
	}

	@Override
	public void latchedExec() throws Exception {
		Resample resample = new Resample();
		resample.setOptions(new String[] { "-S", String.valueOf(randomSeed),
				"-Z", String.valueOf(sampleSizePercent) });
		Instances resampledData = WekaUtil.filter(data, resample,
				"Resampling...");
		WekaUtil.saveData(resampledData, outputFile);
		System.out.println("Finished!");
	}
}
